<?php

function yag_create_post_type() {
	
	register_post_type( YAG_POST_TYPE_NAME,
		array(
			'labels' => array(
				'name' => __( 'Glossary Words' ),
				'singular_name' => __( 'Glossary Word' )
			),
		'public' => true,
		'has_archive' => true,
		'rewrite' => array('slug' => 'glossary'),
		)
	);
	
	remove_post_type_support( YAG_POST_TYPE_NAME, 
		array (
			'trackbacks',
			'comments',
		));
		
		yag_upgrade_to_two();
}
/**
  * Updates words that were saved in the old way to the new way
  *
  * @return boolean
	*/
function yag_upgrade_to_two() {
	
	$yags = get_option('yags', FALSE);
	
	if ( $yags ) {
		foreach ( $yags as $yag ) {

			$post['post_type']			= YAG_POST_TYPE_NAME;
			$post['post_title']			= $yag['keyword'];
			$post['post_name'] 			= strtolower($yag['keyword']);
			$post['post_content']		= $yag['content'];
			$post['post_status']    = 'draft'; 

			wp_insert_post($post);
		}
	}
	update_option('yags-backup', $yags);
	delete_option('yags');	

	return TRUE;
}
